<template>
  <section class="app-container">
    <!--工具条-->
    <el-col :span="24" class="toolbar" style="padding-bottom: 0px;">
      <el-form :inline="true" :model="filters" @submit.native.prevent>
        <el-form-item>
          <el-input v-model="filters.name" placeholder="赛事名称"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="getConclusion">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" v-on:click="handleCon()">结题申请</el-button>
        </el-form-item>
        <el-button type="danger" @click="batchRemove" :disabled="this.sels.length===0">批量删除</el-button>
      </el-form>
    </el-col>

    <!--列表-->
    <el-table :data="conclusionData" border highlight-current-row @selection-change="selsChange" style="width: 100%;">
      <el-table-column type="selection" width="55">
      </el-table-column>
      <el-table-column prop="project.name" label="赛事名称" min-width="120">
      </el-table-column>
      <el-table-column prop="capital.bonus" sortable label="奖金" min-width="100" >
      </el-table-column>
     <!-- <el-table-column prop="teacherNo" label="项目负责人" min-width="120" :formatter="formatTeacherNo">
      </el-table-column>-->
      <el-table-column prop="teamNo" label="团队编号" min-width="120">
      </el-table-column>
      <el-table-column prop="prize.ranking" label="获奖名次" min-width="120" :formatter="formatRanking">
      </el-table-column>
      <el-table-column prop="prize.level" label="获奖级别" min-width="120" :formatter="formatLevel">
      </el-table-column>
      <el-table-column prop="project.projectDate" sortable label="项目立项时间" min-width="120">
      </el-table-column>
      <el-table-column
        prop="status"
        label="审核状态"
        :filter-method="filterStatus"
        width="100"
        :filters="[{ text: '通过', value: '3' }, { text: '不通过', value: '2' },{text: '待审核', value : '1'},{text : '待提交', value : '0'}]"
        filter-placement="bottom-end">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status == '0'"
            :type="scope.row.status === '3' ? 'primary' : 'success'"
            disable-transitions>待提交</el-tag>
          <el-tag v-if="scope.row.status == '1'"
            :type="scope.row.status === '3' ? 'primary' : 'success'"
            disable-transitions >待审核</el-tag>
          <el-tag v-if="scope.row.status == '3'"
            :type="scope.row.status === '3' ? 'primary' : 'success'"
            disable-transitions>已通过</el-tag>
          <el-tag v-if="scope.row.status == '2'"
            :type="scope.row.status === '3' ? 'primary' : 'success'"
            disable-transitions>不通过</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" fixed="right" min-width="180" align="center">
        <template slot-scope="scope">
          <el-button size="small" v-show="scope.row.status === '0'" type="primary" @click="handleCommit(scope.$index, scope.row)">提交</el-button>
          <el-button size="small" v-show="scope.row.status == '0' || scope.row.status == '2'|| scope.row.status == '3'" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
          <el-button size="small" type="success" @click="handleDetail(scope.$index, scope.row)">详情</el-button>
        </template>

      </el-table-column>
    </el-table>
    <!--分页工具-->
    <el-pagination
      background
      @size-change="handleSizeChange"
      :current-page="page"
      @current-change="handleCurrentChange"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="limit"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total">
    </el-pagination>


    <!--编辑界面-->
    <el-dialog
      :title="titleMap[dialogStatus]"
      width="960px"
      :visible.sync="dialogFormVisible"
      :close-on-click-modal="false">
      <el-form :model="editForm" label-width="120px" :rules="editFormRules" ref="editForm">
        <el-row>
          <el-col :span="8">
            <el-form-item label="赛事名称" prop="project.name">
              <el-select v-model="competitionName" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择赛事名称">
                <el-option
                  v-for="item in projectList"
                  :key="item.name"
                  :label="item.name"
                  :value="item.name">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="获奖名次" prop="prize.ranking">
              <el-select v-model="editForm.prize.ranking" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择获奖名次">
                <el-option label="特等奖" value="14">
                </el-option>
                <el-option label="一等奖" value="1">
                </el-option>
                <el-option label="二等奖" value="2">
                </el-option>
                <el-option label="三等奖" value="3">
                </el-option>
                <el-option label="优秀奖" value="5">
                </el-option>
                <el-option label="无" value="0">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="获奖级别" prop="prize.level">
              <el-select v-model="editForm.prize.level" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择获奖名次">
                <el-option label="国家级" value="14">
                </el-option>
                <el-option label="区级" value="1">
                </el-option>
                <el-option label="校级" value="2">
                </el-option>
                <el-option label="无" value="0">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="注册费" prop="capital.enroll">
              <el-input-number v-model="editForm.capital.enroll" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>
            <el-form-item label="差旅费" prop="capital.travel">
              <el-input-number v-model="editForm.capital.travel" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>

          </el-col>
          <el-col :span="8">
            <el-tooltip class="item" effect="dark" content="请先选择赛事名称，并选择对应的项目编号" placement="top">
            <el-form-item label="项目编号" prop="applyId">
              <el-select v-model="editForm.applyId" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择赛事名称">
                <el-option
                  v-for="item in projectData"
                  :key="item.projectId"
                  :label="item.projectId"
                  :value="item.projectId">
                </el-option>
              </el-select>
            </el-form-item>
            </el-tooltip>
            <el-form-item label="培训费" prop="capital.train">
              <el-input-number v-model="editForm.capital.train" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>
            <el-form-item label="指导费" prop="capital.guide">
              <el-input-number v-model="editForm.capital.guide" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>
            <el-form-item label="耗材费" prop="capital.consume">
              <el-input-number v-model="editForm.capital.consume" :min="0" :disabled="dialogStatus == 'detail'"></el-input-number>
            </el-form-item>
            <el-form-item label="奖金" prop="capital.bonus">
              <el-input-number v-model="editForm.capital.bonus" :min="0" :disabled="dialogStatus == 'detail'" ></el-input-number>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="团队编号" prop="teamNo">
              <el-select v-model="selectTeamNo" :disabled="dialogStatus == 'detail'" filterable placeholder="请选择团队编号">
                <el-option
                  v-for="item in teamData"
                  :key="item.id"
                  :label="item.teamNo"
                  :value="item.teamNo">
                </el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="评审费" prop="capital.review">
              <el-input-number v-model="editForm.capital.review" :min="0" :disabled="dialogStatus == 'detail'" ></el-input-number>
            </el-form-item>
            <el-form-item label="领队费" prop="capital.lead">
              <el-input-number v-model="editForm.capital.lead" :min="0" :disabled="dialogStatus == 'detail'" ></el-input-number>
            </el-form-item>
            <el-form-item label="组织费" prop="capital.organize">
              <el-input-number v-model="editForm.capital.organize" :min="0" :disabled="dialogStatus == 'detail'" ></el-input-number>
            </el-form-item>
            <el-form-item label="合计">
              <el-input-number v-model="editForm.capital.sum" disabled ></el-input-number>
            </el-form-item>
          </el-col>
<!--          <el-form-item label="团队成员列表">-->
<!--          </el-form-item>-->
          <el-table :data="memberData" highlight-current-row @selection-change="selsChange" style="width: 100%;border: solid slategray 1px">
            <el-table-column prop="studentNo" label="学生学号" min-width="80">
            </el-table-column>
            <el-table-column prop="studentName" label="学生姓名" min-width="80">
            </el-table-column>
            <el-table-column prop="collegeName" label="所属学院" min-width="120">
            </el-table-column>
            <el-table-column prop="className" label="班级名称" min-width="120">
            </el-table-column>
            <el-table-column prop="grade" label="年级" min-width="100">
            </el-table-column>
            <el-table-column prop="major" label="专业" min-width="100">
            </el-table-column>
            <el-table-column prop="mail" label="邮箱" min-width="120">
            </el-table-column>
            <el-table-column prop="mobileNumber" label="手机号码" min-width="120">
            </el-table-column>
          </el-table>
            <!--        添加or修改-->
            <el-tooltip class="item" effect="dark" content="将签字盖章后的项目结题报告书扫描为 PDF 文档" placement="top">
                <div v-if="dialogStatus != 'detail'" class="file"  style="margin-left: 40px;margin-top: 18px; float: left;">
                    <input v-if="dialogStatus != 'detail'"  type="file" @change="getFileBase()">上传结题附件
                </div>
            </el-tooltip>
            <div style="margin-left: 50px;clear: both">
                <a v-show="dialogStatus == 'update'"  :href="'http://cqfimages.gxuwzapp.top/'+ editForm.file" target="_blank">{{conclusionFile}}</a>
<!--                <a v-show="dialogStatus == 'update'"  :href="'http://127.0.0.1:8888/subject/file/'+ editForm.file" target="_blank">{{conclusionFile}}</a>-->
                <a v-show="dialogStatus == 'add'" :href="fileUrl" target="_blank">{{conclusionFile}}</a>
            </div>

            <!--        详情信息-->
            <el-form-item v-show="dialogStatus == 'detail'" label="项目结题报告书" prop="file" style="margin-top: 18px">
                <el-input v-show="dialogStatus == 'detail'" v-model="conclusionFile" :disabled="dialogStatus == 'detail'" auto-complete="off"></el-input>
                <el-button type="text" @click="download()">下载结题附件</el-button>
<!--                <a :href="'http://127.0.0.1:8888/subject/file/'+ editForm.file" target="_blank" v-show="dialogStatus != 'add' && editForm.file != undefined">预览结题附件</a>-->
            </el-form-item>
        </el-row>
      </el-form>


      <el-form :model="projectForm" label-width="120px" v-show="dialogStatus == 'detail'">
        <el-row>
<!--          <input type="hidden" v-model="projectForm.id">-->
          <el-col :span="8">
            <el-form-item label="申请立项日期" >
              <el-date-picker
                    v-model="projectForm.projectDate"
                    type="datetime"
                    disabled
                    value-format="yyyy-MM-dd HH:mm:ss"
                    placeholder="选择日期时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="指导老师">
              <el-input v-model="projectForm.teacherId" :disabled="dialogStatus == 'detail'" auto-complete="off" style="width: 220px;"></el-input>
            </el-form-item>
            <el-form-item label="竞赛结束日期">
              <el-date-picker
                  v-model="projectForm.endDate"
                  type="datetime"
                  disabled
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="选择日期时间">
              </el-date-picker>
            </el-form-item>
            <el-form-item label="竞赛起始日期">
              <el-date-picker
                  v-model="projectForm.startDate"
                  type="datetime"
                  disabled
                  value-format="yyyy-MM-dd HH:mm:ss"
                  placeholder="选择日期时间">
              </el-date-picker>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="专业">
              <el-input v-model="projectForm.major" disabled auto-complete="off" style="width: 220px;"></el-input>
            </el-form-item>
            <el-form-item label="组赛单位">
              <el-input v-model="projectForm.organization" disabled auto-complete="off" style="width: 220px;"></el-input>
            </el-form-item>
            <el-form-item label="赛制">
              <el-radio-group v-model="projectForm.format" >
                <el-radio :disabled="dialogStatus == 'detail'" class="radio" label="1">单人赛</el-radio>
                <el-radio :disabled="dialogStatus == 'detail'" class="radio" label="2">团体赛</el-radio>
              </el-radio-group>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="主办单位">
              <el-input v-model="projectForm.sponsor" disabled auto-complete="off" style="width: 180px;"></el-input>
            </el-form-item>
            <el-form-item label="联系电话">
              <el-input v-model="projectForm.phone" disabled auto-complete="off" style="width: 180px;"></el-input>
            </el-form-item>
            <el-form-item label="邮件">
              <el-input v-model="projectForm.mail" disabled auto-complete="off" style="width: 180px;"></el-input>
            </el-form-item>
            <el-form-item label="竞赛承办单位">
              <el-input v-model="projectForm.contractor" disabled auto-complete="off" style="width: 180px;"></el-input>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="论证组赛的目的和意义">
          <el-input type="textarea" v-model="projectForm.objective" disabled auto-complete="off"></el-input>
        </el-form-item>
        <el-form-item label="审核意见" v-show="projectForm.opinion != undefined">
          <el-input type="textarea" v-model="projectForm.opinion" disabled auto-complete="off"></el-input>
        </el-form-item>

        <!--        详情信息-->
        <el-form-item v-show="dialogStatus == 'detail'" label="竞赛邀请函或通知附件" prop="project.invitation">
          <el-input v-show="dialogStatus == 'detail'" v-model="fileName" disabled auto-complete="off"></el-input>
          <a :href="'http://cqfimages.gxuwzapp.top/'+ projectForm.invitation" target="_blank" v-show="dialogStatus != 'add' && projectForm.invitation != undefined">预览项目立项附件</a>
<!--          <a :href="'http://miraclepeak.xyz:8888/subject/file/'+ projectForm.invitation" target="_blank" v-show="dialogStatus != 'add' && projectForm.invitation != undefined">预览项目立项附件</a>-->
        </el-form-item>

          <!--        添加or修改-->
<!--          <el-tooltip class="item" effect="dark" content="将签字盖章后的项目立项申请书扫描为 PDF 文档" placement="top">-->
<!--              <div v-if="dialogStatus != 'detail'" class="file"  style="margin-left: 40px;float: left;">-->
<!--                  <input v-if="dialogStatus != 'detail'"  type="file" @change="getFileBase()">上传附件-->
<!--              </div>-->
<!--          </el-tooltip>-->
            <div style="margin-left: 50px;clear: both">
              <a :href="'http://cqfimages.gxuwzapp.top/'+ projectForm.invitation" v-show="dialogStatus != 'detail'" target="_blank">{{fileName}}</a>
<!--              <a :href="'http://miraclepeak.xyz:8888/subject/file/'+ projectForm.invitation" v-show="dialogStatus != 'detail'" target="_blank">{{fileName}}</a>-->
            </div>
      </el-form>

      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false" v-show="dialogStatus != 'detail'">取 消</el-button>
        <el-button @click.native="dialogFormVisible=false"  v-show="dialogStatus == 'detail'">关闭</el-button>
        <el-button v-if="dialogStatus == 'add'" type="primary" @click="conclusionAdd">确认</el-button>
        <el-button v-if="dialogStatus == 'update'" type="primary" @click="conclusionUpdate">修改</el-button>

      </div>
    </el-dialog>

  </section>
</template>

<script>

  export default {
    data(){
      return{
        fileBase64:[],   //存储文件 base64的值将值传给后端处理
        fileBase64Len:0, // 未存储完成文件 base64的长度
        uploadFlag:false, // 上传文件标识
        conclusionData:[],   // 项目结题信息
        teamList:[],   // 通过后台获取的团队数据
        teacherList:[],  // 全部教师信息
        memberList:[], // 添加的团队成员信息
        projectList:[],  // 审核通过的项目信息
        memberData:[],  // 团队成员信息存储
        teamData:[],    // 团队信息存储
        fileName:'',      // 上传的项目立项文件名称
        conclusionFile:"", // 结题附件名称
        fileUrl:"",        // 添加结题附件时访问路径
        titleMap: {
          update: '项目结题修改',
          add: '项目结题申请',
          detail:"项目结题详情",
        },
        memberIndex:0,   // 当前选中团队成员的索引
        member:{        // 单个团队成员信息
          teamNo:"",
          studentNo:"",
          studentName:"",
          collegeName:"",
          className:"",
          grade:"",
          major:"",
          mail:"",
          mobileNumber:"",
        },
        total: 0,
        page: 1,  // 当前页
        limit: 10,  // 每页数量
        projectData: [],  // 项目立项数据
        sels: [], // 列表选中列
        competitionName:"", // 选择的赛事名称
        selectTeamNo:'', // 选中的团队编号
        filters: {
          name: ''
        },
        dialogStatus:"",
        memberStatus:"",
        dialogFormVisible: false,
        innerVisible:false,
        textMap: {
          update: '项目结题',
          detail: "项目结题详情",
        },
        // 项目信息
        projectForm:{
          // id:0,
          projectId:"",
          // budgetId:0,
          // status:"",
          // opinion:"",
          // 项目基本信息
          name:"",
          teacherId:"",
          major:"",
          format:"",
          projectDate:"",
          sponsor:"",
          contractor:"",
          objective:"",
          invitation:[],
          phone:"",
          mail:"",
          organization:"",
          startDate:"",
          endDate:"",
        },
        // 编辑界面数据
        editForm: {
          conclusionId:0,
          applyId:"",
          teamNo:"",
          file:"",
          prizeId:"",
          capitalId:"",
          teacherId:"",
          status:"",
          // 项目基本信息
          project: {
            projectId:"",
            name: "",
            teacherId: "",
            major: "",
            format: "",
            projectDate: "",
            sponsor: "",
            contractor: "",
            objective: "",
            invitation: [],
            phone: "",
            mail: "",
            organization: "",
            startDate: "",
            endDate: "",
          },

          // 获奖情况
          prize: {
            prizeId: 0,
            ranking: "",
            level: "",
          },
          // 实际资金使用
          capital: {
            capital: 0,
            enroll: 0,
            travel: 0,
            train: 0,
            guide: 0,
            bonus: 0,
            other: 0,
            consume: 0,
            review: 0,
            lead: 0,
            organize: 0,
            sum: 0,
          },
        },
        projectFormRules:{
          name: [{ required: true, message: '请输入赛事名称', trigger: 'blur' }],
          // charge: [{ required: true, message: '请输入项目负责人', trigger: 'blur' }],
          major: [{ required: true, message: '请输入专业', trigger: 'blur' }],
          format: [{ required: true, message: '请选择赛制', trigger: 'blur' }],
          mail: [{ required: true, message: '请输入邮件', trigger: 'blur' }],
          phone: [{ required: true, message: '请输入联系电话', trigger: 'blur' }],
          projectDate: [{ required: true, message: '请输入申请立项日期', trigger: 'blur' }],
          sponsor: [{ required: true, message: '请输入主办单位', trigger: 'blur' }],
          // charge: [{ required: true, message: '请输入项目负责人', trigger: 'blur' }],
          organization: [{ required: true, message: '请输入组赛单位', trigger: 'blur' }],
          startDate: [{ required: true, message: '请输入竞赛起始日期', trigger: 'blur' }],
          endDate: [{ required: true, message: '请输入竞赛结束日期', trigger: 'blur' }],
          contractor: [{ required: true, message: '请输入竞赛承办单位', trigger: 'blur' }],
          objective: [{ required: true, message: '请输入论证组赛的目的和意义', trigger: 'blur' }],
          projectDate: [{ required: true, message: '请输入申请立项日期', trigger: 'blur' }],
          invitation: [{ required: true, message: '请上传竞赛邀请函或通知附件', trigger: 'blur' }],

        },
        // 数据校验
        editFormRules: {
          // name:[{required: true, message: '请选择赛事名称', trigger: 'blur' }],
          teamNo:[{required: true, message: '请选择团队编号', trigger: 'blur' }],
          applyId: [{ required: true, message: '请选择项目编号', trigger: 'blur' }],
          // 获奖
          prize: {
            ranking: [{required: true, message: '请选择获奖名次', trigger: 'blur'}],
            level: [{required: true, message: '请选择获奖级别', trigger: 'blur'}],
          },
          // 资金
          capital: {
            enroll: [{required: true, message: '请输入注册费', trigger: 'blur'}],
            travel: [{required: true, message: '请输入差旅费', trigger: 'blur'}],
            train: [{required: true, message: '请输入培训费', trigger: 'blur'}],
            guide: [{required: true, message: '请输入指导费', trigger: 'blur'}],
            consume: [{required: true, message: '请输入耗材费', trigger: 'blur'}],
            bonus: [{required: true, message: '请输入奖金', trigger: 'blur'}],
            review: [{required: true, message: '请输入评审费', trigger: 'blur'}],
            lead: [{required: true, message: '请输入指导费', trigger: 'blur'}],
            organize: [{required: true, message: '请输入组织费', trigger: 'blur'}],
          },
        },
      }

    },
    mounted(){
      this.getConclusion();
      this.getProject();
      // this.getTeacherList();
      this.getTeam();
    },
    watch:{
      // 监听选中的团队编号
      selectTeamNo(value){
        this.memberData = [];
        this.memberList.forEach((obj)=>{
          if (obj.teamNo == value){
            this.memberData.push(obj);
          }
        });
        this.editForm.teamNo = value;
        console.log("teamNO--->", this.editForm.teamNo)
      },
      // 监听选中的赛事名称
      competitionName(value) {
        this.projectData = [];
        // this.teamData = [];
        this.projectList.forEach((obj) => {
          if (obj.name == value) {
            this.projectData.push(obj);
          }
        });
        // this.teamList.forEach((obj)=>{
        //   if (obj.name == value){
        //     this.teamData.push(obj);
        //   }
        // });

      },
        // 监听上传文件标识
        uploadFlag:function(){
            if (this.uploadFlag == true){
                // 开启上传文件
                this.fileUpload();
                // 关闭上传文件
                this.uploadFlag = false;
            }
        },
        // 监听是否上传文件
        fileBase64:function(){
            if (this.fileBase64.length > this.fileBase64Len){
                // 开启上传文件
                this.uploadFlag = true;
            }
        },
      enroll(value){
        console.log("enroll=======" + value);
        this.editForm.sum = this.editForm.capital.sum + value;
      },
      train(value){
        console.log("enroll=======" + value);
        this.editForm.capital.sum = this.editForm.capital.sum + value;
      },
      travel(value){
        console.log("enroll=======" + value);
        this.editForm.capital.sum = this.editForm.capital.sum + value;
      },
      guide(value){
        console.log("enroll=======" + value);
        this.editForm.capital.sum = this.editForm.capital.sum + value;
      },

    },
    computed: {
      enroll(){
        this.editForm.capital.sum = this.editForm.capital.enroll + this.editForm.capital.train + this.editForm.capital.travel + this.editForm.capital.organize +
                this.editForm.capital.lead + this.editForm.capital.guide + this.editForm.capital.consume +
                this.editForm.capital.bonus + this.editForm.capital.review + this.editForm.capital.review ;
      },

    },
    methods:{
        // 将当前上传文件转换为base64
        getFileBase(){
            var _this = this;
            _this.fileBase64Len = _this.fileBase64.length;
            var event = event || window.event;
            var file = event.target.files[0];
            _this.conclusionFile = file.name;
            console.log("name" + file.name + ":" + JSON.stringify(file));
            var reader = new FileReader();
            //转base64
            reader.onload = function(e) {
                _this.fileBase64.push(e.target.result);
            }
            reader.readAsDataURL(file);
        },
        // 上传文件
        fileUpload:function(){
            console.log("name-->" + this.conclusionFile);
            var _this = this;
            // console.log("baseFile" + _this.fileBase64[_this.fileBase64.length - 1]);
            _this.http({
                url:"upload/upload",
                method: "post",
                data:{
                    "name":this.conclusionFile,
                    "baseString":this.fileBase64[_this.fileBase64.length - 1],
                },
            }).then(function (res) {
                // 关闭上传文件
                _this.uploadFlag = false;
                if (res.data.code === 666){
                    _this.conclusionFile = res.data.data.name;
                    console.log("file----------->", _this.conclusionFile)
                    _this.editForm.file = res.data.data.fileName;
                    console.log("file-->", _this.editForm.file)
                    _this.fileUrl = "http://127.0.0.1:8888/subject/file/" + res.data.data.fileName;
                    _this.$message.success(res.data.data.name + "文件上传成功");
                } else {
                    _this.$message.error(res.data.message);
                }

            }).catch(function (error) {
                // 关闭上传文件
                _this.uploadFlag = false;
                _this.$message.error("error-->", error)
            });
        },
        download(){
            let param = {
                fileName:this.editForm.file
            }
            let fileName = this.editForm.file == undefined ? "" : this.editForm.file.substring(this.editForm.file.indexOf("_") + 1);
            this.http({
                url:"upload/download",
                method:"post",
                data:{
                    fileName:this.editForm.file
                },
                responseType: 'blob'
            }).then(res =>{
                let url = window.URL.createObjectURL(new Blob([res.data]))
                let link= document.createElement('a')
                link.style.display='none'
                link.href=url
                link.setAttribute('download', fileName)    // 自定义下载文件名（如exemple.txt）
                document.body.appendChild(link)
                link.click()



                /*let blob = new Blob([res], {type: res.type})
                let downloadElement = document.createElement('a')
                let href = window.URL.createObjectURL(blob); //创建下载的链接
                downloadElement.href = href;
                downloadElement.download = fileName; //下载后文件名
                document.body.appendChild(downloadElement);
                downloadElement.click(); //点击下载
                document.body.removeChild(downloadElement); //下载完成移除元素
                window.URL.revokeObjectURL(href); //释放blob对象*/



                /*const blob = res.data
                const reader = new FileReader()
                reader.readAsDataURL(blob)
                reader.onload = (e) => {
                    const a = document.createElement('a')
                    a.download = `现金流文件`
                    a.href = e.target.result
                    document.body.appendChild(a)
                    a.click()
                    document.body.removeChild(a)
                }*/
            }).catch(error => {
                console.log("download --error-->", error)
            })

        },
      // 查询项目结题信息
      getConclusion(){
        let teacher = localStorage.getItem("teacherId");
        // 判断当前用户是否是教师
        if (teacher === 'undefined' || teacher === 'null' || teacher === undefined || teacher === null){
          teacher = "";
        }
        let _this = this;
        let params = {
          name: this.filters.name,
          page: this.page,
          limit: this.limit,
          teacherId: teacher,
          status:"",
        }
        this.http.get("conclusion/list",{params: params})
          .then(function (res) {
          _this.conclusionData = res.data.data.list;
          _this.memberList = res.data.data.member;
          _this.total = res.data.data.total;
        }).catch(error => {
          console.log("conclusion- error --->", error)
        });

      },
      // 查询全部教师
      getTeacherList(){
        const _this = this;
        _this.http.get("teacher/list"
        ).then(res => {
          _this.teacherList = res.data;
        }).catch(error => {
          console.log("teacher error", error)
        });

      },
      // 查询团队信息
      getTeam: function () {
        let teacher = localStorage.getItem("teacherId");
        // 判断当前用户是否是教师
        if (teacher === 'undefined' || teacher === 'null' || teacher === undefined || teacher === null){
          teacher = "";
        }
        let _this = this;
        this.http({
          url: "team/list",
          method: "post",
          data: {
            title: this.filters.name,
            page: this.page,
            limit: this.limit,
            teacherId: teacher,
          },
        }).then(res => {
          _this.teamData = res.data.data.list;
          // _this.memberList = _this.teamData.memberList;
          // _this.total = res.data.data.total;
        });
      },
      // 查询项目信息
      getProject: function () {
        let charge = localStorage.getItem("teacherId");
        // 判断当前用户是否是教师
        if (charge === 'undefined' || charge === 'null' || charge === undefined || charge === null) {
          charge = "";
        }
        var _this = this;
        let params = {
          status:"3",
          name: this.filters.name,
          page: this.page,
          limit: this.limit,
          teacherId:charge,
        }
        _this.http.get("project/list", {params:params}).then(res =>{
          _this.projectList = res.data.data.list;
          // _this.total = res.data.data.total;
        }).catch(error => {
          console.log("error->", error)
        })
      },
      // 添加结题信息
      conclusionAdd(){
        /*if (this.editForm.file == null || this.editForm.file === "" || this.editForm.file === undefined){
          this.$message.warning("请上传结题报告书")
          return;
        }*/
        console.log("refs----->", this.editForm)
        this.$refs.editForm.validate(valid => {
          console.log("valid-->", valid)
          if (valid) {
            this.$confirm('确认提交吗？', '提示', {})
              .then(() => {
                  let charge = localStorage.getItem("teacherId");
                  // 判断当前用户是否是教师
                  if (charge === 'undefined' || charge === 'null' || charge === undefined || charge === null) {
                      charge = "";
                  }
                  this.editForm.teacherId = charge;
                  this.editForm.teamNo = this.selectTeamNo;
                  this.editForm.status = "0";

                  // const para = Object.assign({}, this.editForm);
                  let _this = this;
                this.http.post("conclusion/add",_this.editForm).then(res =>{
                    if (res.data.code === 666) {
                        _this.dialogFormVisible = false;
                        _this.getConclusion();
                        _this.$message({
                            message: "操作成功",
                            type: 'success'
                        });
                    } else {
                        _this.$message({
                            message: res.data.message,
                            type: 'error'
                        });
                    }
                }).catch(error => {
                    console.log("conclusion---add-->", error)
                })

              })
          }
        });
      },
      conclusionUpdate:function(){
          this.$refs.editForm.validate(valid => {
              if (valid) {
              this.$confirm('确认提交吗？', '提示', {})
                .then(() => {
                    this.editForm.teamNo = this.selectTeamNo;
                    this.editForm.status = "0";

                    // const para = Object.assign({}, this.editForm);
                    let _this = this;

                    this.http.post("conclusion/update",_this.editForm).then(res =>{
                        if (res.data.code === 666) {
                            _this.dialogFormVisible = false;
                            _this.getConclusion();
                            _this.$message({
                                message: "操作成功",
                                type: 'success'
                            });
                        } else {
                            _this.$message({
                                message: res.data.message,
                                type: 'error'
                            });
                        }
                    }).catch(error => {
                        console.log("conclusion---add-->", error)
                    })

                })
              }
          });
      },
      // 提交项目结题申请
      handleCommit(index, row){
        this.$confirm('确认结题该项目吗?', '提示', {
          type: 'warning'
        }).then(() => {
          if (row.status === "0") {
            let _this = this;
            this.http({
              url: "conclusion/commit",
              data: {
                conclusionId: row.conclusionId,
                status: "1",
              },
              method: "post",
            }).then(function (res) {
              if (res.data.code === 666) {
                _this.getConclusion();
                _this.$message({
                  message: "提交成功",
                  type: 'success'
                });
              } else {
                _this.$message({
                  message: "提交失败",
                  type: 'error'
                });
              }
            });
          } else if (data.status === "1") {
            _this.$message({
              message: "已经提交，不必重复提交",
              type: 'error'
            });
          }
        })  .catch(() => {
      })
      },
      // 显示编辑界面
      handleEdit(index, row) {
        this.memberData = [];
        this.dialogStatus = 'update'
        this.dialogFormVisible = true;

        this.memberList.forEach((obj)=>{
          if(row.teamNo === obj.teamNo){
            this.memberData.push(obj);
          }
        });
        this.selectTeamNo = row.teamNo;
        this.competitionName = row.name;
        this.projectList.forEach((obj)=>{
            if (obj.projectId == row.applyId ){
                this.competitionName = obj.name;
            }
        })

        this.editForm = Object.assign({}, row)
      },
      // 显示项目结题申请界面
      handleCon(){
        // 置空
        this.conclusionFile = "";
        this.fileName = ""
        this.competitionName = "";
        this.selectTeamNo = ""
        this.memberData = [];
        // this.$refs['editForm'].resetFields()
        this.editForm = {
          project:{},
          capital:{
            sum:0
          },
          prize:{},
        }


        this.dialogFormVisible = true;
        this.dialogStatus = 'add';
      },
      // 显示详情框
      handleDetail(index, row){
        this.dialogStatus = 'detail';
        this.dialogFormVisible = true;
        this.memberData = [];
        // 获取当前选中的项目立项附件信息
        if(row.project.invitation != undefined && row.project.invitation != null) {
          this.fileName = row.project.invitation.substring(row.project.invitation.lastIndexOf("_") + 1);
        }else{
          this.fileName = "";
        }
        // 获取当前选中的项目结题附件信息
        if(row.file != undefined && row.file != null) {
          this.conclusionFile = row.file.substring(row.file.lastIndexOf("_") + 1);
        }else{
          this.conclusionFile = "";
        }

        this.memberList.forEach((obj)=>{
          if(row.teamNo === obj.teamNo){
            this.memberData.push(obj);
          }
        });
        this.selectTeamNo = row.teamNo;
        this.competitionName = row.project.name ;
        this.projectForm = Object.assign({}, row.project)

        this.editForm = Object.assign({}, row);
      },

      // 全选单选多选
      selsChange(sels) {
        this.sels = sels
      },
      // 跳转到某页
      handleCurrentChange(val) {
        // 获取当前页
        this.page = val;
        // 重新获取数据
        this.getConclusion();
      },
      // 改变每页条数
      handleSizeChange(val){
        this.limit = val;
        this.getConclusion();
      },
      formatStatus: function (row) {
        if (row.status === "0") {
          return "待提交";
        } else if (row.status === "1") {
          return "待审核";
        } else if (row.status === "2") {
          return "不通过";
        } else if (row.status === "3") {
          return "已批准";
        }
      },
      formatRanking(row){
        if(row.prize.ranking === "14"){
          return "特等奖";
        }else if (row.prize.ranking === "1"){
          return "一等奖";
        } else if (row.prize.ranking === "2"){
          return "二等奖";
        } else if (row.prize.ranking === "3"){
          return "三等奖";
        }else if (row.prize.ranking === "5"){
          return "优秀奖";
        }else if (row.prize.ranking === "0"){
          return "无";
        }

      },
      formatLevel(row){
        if (row.prize.level === "14"){
          return "国家级";
        }else if (row.prize.level === "1"){
          return "区级";
        } else if (row.prize.level === "2"){
          return "校级";
        }else if (row.prize.level === "0"){
          return "无";
        }

      },
      formatTeacherNo:function(row){
        this.teacherList.forEach((obj)=>{
          if (obj.teacherId == row.teacherNo){
            row.teacherNo = obj.teacherName;
          }
        });

      },
      filterStatus(value, row){
        return row.status === value;
      },
      batchRemove(){
        let flag = true,
            _this = this;
        this.$confirm('确认删除选中记录吗？', '提示', {
          type: 'warning'
        }).then(() => {
          this.sels.map(item =>{
            if(item.status === "3"){
              flag = false;
            }else if(item.status === "1"){
              flag = false;
            }
            // if (item.conclusionId === 0){
            //   item.conclusionId = undefined;
            // }
            // if (item.prizeId === 0){
            //   item.prizeId = undefined;
            // }
            // if (item.capitalId === 0){
            //   item.capitalId = undefined;
            // }
          });

          let ids = this.sels.map(obj =>{
              return obj.conclusionId
          })

          if(flag) {
            this.http.post("conclusion/delete", ids).then(res =>{
                if (res.data.code === 666) {
                    _this.getConclusion();
                    _this.$message({
                        message: "删除成功",
                        type: 'success'
                    });
                } else {
                    _this.$message({
                        message: res.data.message,
                        type: 'error'
                    });
                }
            })
              // method: "post",
              // data: {
              //   ids: JSON.stringify(this.sels)
              // },
          }else{
            _this.$message({
              message: "删除失败,不能删除已经结题的项目以及在审核的项目",
              type: 'error'
            });
          }

        }).catch(() => {
          console.log("cancel");
        });


      },


    },
  }
</script>

<style scoped>
  a:link {color:blue;} /* 未访问的链接 */
  a:visited {color:orange;} /* 已访问的链接 */
  a:hover {color:green;} /* 鼠标划过链接 */
  a:active {color:red;} /* 已选中的链接 */

  .file {
    position: relative;
    display: inline-block;
    background: #D0EEFF;
    border: 1px solid #99D3F5;
    border-radius: 4px;
    padding: 4px 12px;
    overflow: hidden;
    color: #1E88C7;
    text-decoration: none;
    text-indent: 0;
    line-height: 20px;
  }
  .file input {
    position: absolute;
    font-size: 100px;
    right: 0;
    top: 0;
    opacity: 0;
    cursor: pointer
  }
  .file:hover {
    background: #AADFFD;
    border-color: #78C3F3;
    color: #004974;
    text-decoration: none;
  }
</style>
